//
//  SFFindController.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/5/19.
//



import UIKit
import SwiftUI


//extension UICollectionViewFlowLayout {
//
//    private static var _hzj_short = "short"
//
//    /**
//     *相对于collectionView的尺寸，在滑动方向减少的距离
//     *比如collectionView的尺寸(200,300),水平滑动，若想滑动160后边停止，则设置hzj_short=(200-160)=40
//     */
//    var hzj_short: CGFloat? {
//        set {
//            objc_setAssociatedObject(self, &UICollectionViewFlowLayout._hzj_short, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
//        }
//        get {
//            return objc_getAssociatedObject(self, &UICollectionViewFlowLayout._hzj_short) as? CGFloat ?? 0
//        }
//    }
//    open override func prepare() {
//        super.prepare()
//
//        if let short = self.hzj_short {
//            self.collectionView?.decelerationRate = .fast
//            //使用kvc
//            if ((self.collectionView?.value(forKey: "interpageSpacing") as? CGSize) != nil) {
//                let size = self.scrollDirection == .horizontal ? CGSize(width: -short,height: 0) : CGSize(width: 0 ,height: -short)
//                self.collectionView?.setValue(size, forKey: "interpageSpacing")
//            }
//            if ((self.collectionView?.value(forKey: "pagingOrigin") as? CGPoint) != nil) {
//                self.collectionView?.setValue(CGPoint.zero, forKey: "pagingOrigin")
//            }
//        }
//    }
//
//
//}

var statueHeight:CGFloat {
    if #available(iOS 13.0, *) {
        if let result = UIApplication.shared.windows.first?.windowScene?.statusBarManager?.statusBarFrame {
            return result.height
        }else{
            return 0
        }
    } else {
        return UIApplication.shared.statusBarFrame.height
    }
}


class SFFindController: SFBaseController, UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 21
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath)
        switch indexPath.row % 5 {
        case 0:
            cell.backgroundColor = .brown
        case 1:
            cell.backgroundColor = .green
        case 2:
            cell.backgroundColor = .red
        case 3:
            cell.backgroundColor = .yellow
        default:
            cell.backgroundColor = .orange
        }
        return cell
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "滑动-分页"
        self.view.backgroundColor = .white
        self.edgesForExtendedLayout = .init(rawValue: 0)
        self.view.addSubview(clv)
    }
    
    lazy var clv: UICollectionView = {
        let layout = BroadcastLayout()
        layout.itemSize = CGSize(width: Adapter.Screen.width/3, height: 300)
        ///滑动方向(默认竖直方向)
        layout.scrollDirection = .horizontal
        layout.minimumLineSpacing = 0
        layout.minimumInteritemSpacing = 0
        layout.scale = 2 * Adapter.Screen.width / 3
        
        let v = UICollectionView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 400), collectionViewLayout: layout)
        v.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell")
        v.dataSource = self
        v.delegate = self
        v.backgroundColor = .gray
        v.isPagingEnabled = true
        return v
    }()
    
}

